package com.hr.demo.controller;

import com.hr.demo.annotation.Token;
import com.hr.demo.config.State;
import com.hr.demo.entity.ResponseJson;
import com.hr.demo.entity.User;
import com.hr.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResponseJson login(User user) {
        if (user.getAccount() == null || user.getPwd() == null) {
            return new ResponseJson(State.FAIL, "用户名密码不能为空");
        } else {
            return userService.login(user.getAccount(), user.getPwd());
        }
    }

    @Token
    @PostMapping("/getmyinfo")
    public ResponseJson getMyInfo() {
        return userService.geuMyInfo();
    }

    @PostMapping("/add")
    public ResponseJson add(User user) {
        if (user.getAccount() != null || user.getPwd() != null) {
            if (user.getUsername() != null)
                return userService.add(user);
            return new ResponseJson(State.FAIL, "姓名不能为空");
        }
        return new ResponseJson(State.FAIL, "用户名,密码不能为空");
    }

//    @Token
//    @PostMapping("/settx")
//    public ResponseJson setHeadPortrait(String filePath) {
//        if (filePath == null) {
//            return new ResponseJson(State.FAIL, "请上传正确的文件");
//        }
//        return userService.setHeadPortrait(filePath);
//    }
}
